<?php 
class SearchAction extends Action {
	
	public function search() {
		$word = $_POST['word'];
		$pagenum = $_POST['pagenum'];
		if(empty($word) && empty($pagenum)) {
			$word = session('word');
			$pagenum = session('pagenum');
		}
		session('word',$word);
		session('pagenum',$pagenum);
		$word = common('String')->request_string($word);
		$data['title'] = array('like','%'.$word.'%');
		$data['content'] = array('like','%'.$word.'%');
		$data['_logic'] = 'OR';
		$list = M('cms_article')->where($data)->findPage($pagenum);
		$this->assign('list',$list);
		
		if (($htmlfile = S('cache_search_templatePath_'.$_POST['sid'])) === false) {
			$map['siteid'] = $_POST['sid'];
			$template_name = M('cms_templates')->where($map)->getField('template_name');
			$templatePath = D('cms://Site')->getSiteInfo($_POST['sid']);
			$htmlfile =  $templatePath.'templates/'.iconv("UTF-8","GB2312",$template_name);
			S('cache_search_templatePath_'.$_POST['sid'], $htmlfile);
		}
		$this->display($htmlfile);
	}
}
?>